﻿package com.tudou.home.newskin.containers
{
    import com.tudou.consts.*;
    import com.tudou.cookie.*;
    import com.tudou.home.common.events.*;
    import com.tudou.skin.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class InfoSprite extends Sprite implements ITipInfo, ISetting
    {
        private var rateSettingData:RateSettingData;
        private var tip:TextField;
        private var skipSettingData:SkipSettingData;
        private var settingSkip:InteractiveObject;
        private var openSkip:InteractiveObject;
        private var rateType:int;
        private static const FAST_TUDOU:String = "<a target=\'_blank\' href=\'http://www.tudou.com/my/soft/speedup.php\'>" + "<font size=\'12\' color=\'#FF6600\' face=\'宋体\'>" + "<u>飞速土豆</u>" + "</font>" + "</a>";
        private static const FAST_TIP_CONNECTED:String = FONT_START + "飞速土豆正在寻找最近资源，请等候！" + FONT_END;
        private static const FONT_END:String = "</font>";
        private static const ORIGINAL_VIDEO:String = "<font size=\'12\' color=\'#FF6600\' face=\'宋体\'>原画</font></a>";
        private static const FONT_START:String = "<font size=\'12\' color=\'#FFFFFF\' face=\'宋体\'>";
        private static const FAST_TIP:String = FONT_START + "试试用" + FAST_TUDOU + "加快缓冲，让播放更流畅！" + FONT_END;
        private static const TUDOU_SERVICE:String = "<a target=\'_blank\' href=\'event:tudouService\'><font size=\'12\' color=\'#FF6600\' face=\'宋体\'><u>土豆客服</u></font></a>";

        public function InfoSprite()
        {
            tip = new TextField();
            tip.selectable = false;
            tip.autoSize = TextFieldAutoSize.LEFT;
            tip.borderColor = 16711680;
            tip.addEventListener(TextEvent.LINK, textLinkHlr);
            addChild(tip);
            openSkip = new SkipOpenBTN();
            openSkip.visible = false;
            openSkip.y = -2;
            openSkip.addEventListener(MouseEvent.CLICK, openSkipHlr);
            addChild(openSkip);
            settingSkip = new SkipSettingBTN();
            settingSkip.visible = false;
            settingSkip.y = -2;
            settingSkip.addEventListener(MouseEvent.CLICK, settingSkipHlr);
            addChild(settingSkip);
            return;
        }// end function

        private function openSkipHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkipEvent(SkipEvent.OPEN));
            return;
        }// end function

        private function settingSkipHlr(event:MouseEvent) : void
        {
            dispatchEvent(new SkipEvent(SkipEvent.SETTING));
            return;
        }// end function

        public function showSettingSkipTip() : void
        {
            var _loc_1:String = "自动跳过片头片尾 ";
            _loc_1 = _loc_1 + "　　　　　　　";
            _loc_1 = _loc_1 + "     ";
            tip.htmlText = FONT_START + _loc_1 + FONT_END;
            settingSkip.visible = true;
            settingSkip.x = 110;
            return;
        }// end function

        public function showSettingedSkipTip() : void
        {
            return;
        }// end function

        public function showError(param1:int) : void
        {
            var _loc_2:String = null;
            hideSkips();
            switch(param1)
            {
                case 1:
                {
                    _loc_2 = FONT_START + "对不起，视频暂时无法播放。请稍后刷新页面重试，或联系" + TUDOU_SERVICE + "。" + FONT_END;
                    break;
                }
                case 3:
                {
                    _loc_2 = FONT_START + "抱歉，这个视频正在审核复查中，暂时不能播放。若有疑问，请联系" + TUDOU_SERVICE + "。" + FONT_END;
                    break;
                }
                case 5:
                {
                    _loc_2 = FONT_START + "对不起，这个视频暂时不能播放，请稍后访问。若有疑问，请联系" + TUDOU_SERVICE + "。" + FONT_END;
                    break;
                }
                case 6:
                {
                    _loc_2 = FONT_START + "抱歉，由于版权原因，非大陆地区暂时无法观看该视频，还望谅解。若有疑问，请联系" + TUDOU_SERVICE + "。" + FONT_END;
                    break;
                }
                case 2:
                case 4:
                {
                }
                default:
                {
                    _loc_2 = FONT_START + "对不起，这个视频不存在或已被删除。若有疑问，请联系" + TUDOU_SERVICE + "。" + FONT_END;
                    break;
                    break;
                }
            }
            tip.htmlText = _loc_2;
            return;
        }// end function

        public function setRateSetting(param1:RateSettingData) : void
        {
            rateSettingData = param1;
            return;
        }// end function

        public function setSkipSeting(param1:SkipSettingData) : void
        {
            skipSettingData = param1;
            return;
        }// end function

        public function showFastTip(param1:Boolean = false) : void
        {
            hideSkips();
            if (param1)
            {
                tip.htmlText = FAST_TIP_CONNECTED;
            }
            else
            {
                tip.htmlText = FAST_TIP;
            }
            return;
        }// end function

        public function clearTipInfo(param1:int) : void
        {
            hideSkips();
            tip.htmlText = "";
            return;
        }// end function

        public function showTip(param1:int) : void
        {
            var _loc_2:String = null;
            hideSkips();
            if (param1 == 0)
            {
                if (rateType == RateType.ORIGINAL)
                {
                    _loc_2 = "网速有点不给力，请多暂停一会或切换到480P/360P继续观看。";
                }
                if (rateType == RateType.P480)
                {
                    _loc_2 = "网速有点不给力，请多暂停一会儿或切换到清晰360P观看。";
                }
                else if (rateType == RateType.P360)
                {
                    _loc_2 = "网速有点不给力，请多暂停一会儿或切换到流畅256P观看。";
                }
                else
                {
                    _loc_2 = "网速有点不给力，请多暂停一会儿或切换观看。";
                }
            }
            tip.htmlText = FONT_START + _loc_2 + FONT_END;
            return;
        }// end function

        private function textLinkHlr(event:TextEvent) : void
        {
            dispatchEvent(new TextEvent(event.type, false, false, event.text));
            return;
        }// end function

        public function showHasOriginalTip() : void
        {
            hideSkips();
            var _loc_1:* = "清晰360P及以上视频有" + ORIGINAL_VIDEO + "版本，最接近原始画质，尝试切换观看。  ";
            _loc_1 = _loc_1 + ("<a href=\'event:noTip\'>" + "<font size=\'12\' color=\'#999999\' face=\'宋体\'>" + "<u>不再提示</u>" + "</font>" + "</a>");
            _loc_1 = _loc_1 + "  ";
            tip.htmlText = FONT_START + _loc_1 + FONT_END;
            return;
        }// end function

        public function setRate(param1:int) : void
        {
            rateType = param1;
            return;
        }// end function

        private function hideSkips() : void
        {
            openSkip.visible = false;
            settingSkip.visible = false;
            return;
        }// end function

        public function showHasSkipTip() : void
        {
            var _loc_1:String = "是否自动跳过片头片尾？  ";
            _loc_1 = _loc_1 + "　　　　　　　";
            _loc_1 = _loc_1 + ("<a href=\'event:noSkipTip\'>" + "<font size=\'12\' color=\'#999999\' face=\'宋体\'>" + "<u>不再提示</u>" + "</font>" + "</a>");
            _loc_1 = _loc_1 + "     ";
            tip.htmlText = FONT_START + _loc_1 + FONT_END;
            openSkip.visible = true;
            openSkip.x = 150;
            return;
        }// end function

    }
}
